package com.ds.infra.ibatis.demo.mapper;

import com.ds.infra.ibatis.annotation.*;
import com.ds.infra.ibatis.demo.model.User;

import java.util.List;
/**
 * 作用：用户操作的Mapper接口
 *
 * @author WeiShaoying
 */
public interface UserMapper {

    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(@Param("id") Long id);

    @Select("SELECT * FROM user")
    List<User> selectAll();

    @Insert("INSERT INTO user(name, age, email) VALUES(#{name}, #{age}, #{email})")
    int insert(User user);

    @Update("UPDATE user SET name=#{name}, age=#{age}, email=#{email} WHERE id=#{id}")
    int update(User user);

    @Delete("DELETE FROM user WHERE id=#{id}")
    int deleteById(@Param("id") Long id);

    @Select("SELECT LAST_INSERT_ID()")
    Long getLastInsertId();

}
